﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Diagnostics;
using ExceptionHandler;
using Microsoft.ApplicationBlocks.ExceptionManagement;

[assembly: CLSCompliant(true)]
namespace ASUV
{
	public partial class ASMainForm : Form
	{

		#region [members]
		Form configForm, queryListForm, compareForm;
		Form addQueryForm;
		internal bool show2005 = false;
		bool projectStatus;
		bool connStatus;
		ProjectFileFoundEventArgs projectDetails;
		#endregion

		#region public ASMainForm()
		public ASMainForm()
		{
			InitializeComponent();
		}
		#endregion

		#region private void mainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
		private void mainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
		{
			LoadForms();
		}
		#endregion

		#region private void mainTreeView_Click(object sender, EventArgs e)
		private void mainTreeView_Click(object sender, EventArgs e)
		{
			mainTreeView.SelectedNode = null;
		}
		#endregion

		#region private void newToolStripMenuItem_Click_1(object sender, EventArgs e)

		private void newToolStripMenuItem_Click_1(object sender, EventArgs e)
		{

			if (projectStatus)
			{
				DialogResult result = MessageBox.Show("This action will close the current project. Do you want to continue ?", "AS Upgrade Verification Tool", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
				if (result == DialogResult.OK)
				{

					CleanUPPreviousProjectDetails();
					ShowConfiguration();
					configForm.Text = "New Project";
				}
			}
			else
			{
				ShowConfiguration();
				configForm.Text = "New Project";
			}
			
		}
		#endregion

		#region private void FileFound(object sender, ProjectFileFoundEventArgs args)
		/// <summary>
		/// To load project details from project file
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="args">Gets or Sets project details</param>
		private void FileFound(object sender, ProjectFileFoundEventArgs args)
		{
			mainTreeView.Nodes[0].Nodes.Clear();

			//Add new nodes from the newly created or existing project file
			mainTreeView.Nodes[0].Nodes.Add(args.ProjectName);
			mainTreeView.Nodes[0].Nodes[0].Nodes.Add("Configuration");
			mainTreeView.Nodes[0].Nodes[0].Nodes.Add("Queries");
			mainTreeView.Nodes[0].Nodes[0].Nodes.Add("Results");

			mainTreeView.ExpandAll();

			mainTreeView.Nodes[0].Nodes[0].Nodes[1].ContextMenuStrip = this.queriesContextMenuStrip;
			mainTreeView.Nodes[0].Nodes[0].Nodes[2].ContextMenuStrip = this.resultContextMenuStrip;
			queryToolStripMenuItem.Enabled = true;
			addQueryToolStripMenuItem1.Enabled = true;
			
			resultToolStripMenuItem.Enabled = true;
			projectDetails = args;
			XmlDocument xmlDomProjectContent = ProjectFile.GetProjectDetails(projectDetails.ProjectLocation + "\\" + projectDetails.ProjectFileName);
			if (int.Parse(xmlDomProjectContent.SelectSingleNode("ProjectFile/TotalQueries").InnerText) != 0)
			{
				removeAllToolStripMenuItem.Enabled = true;
				removeAllToolStripMenuItem1.Enabled = true;
				executeAllQueryAS2000ToolStripMenuItem1.Enabled = true;
				executeAllQueryAS2005ToolStripMenuItem1.Enabled = true;
				executeAllQueryAS2000ToolStripMenuItem.Enabled = true;
				executeAllQueryAS2005ToolStripMenuItem.Enabled = true;
				compareQueryResultToolStripMenuItem1.Enabled = true;
				clearQueryResultToolStripMenuItem1.Enabled = true;
				compareQueryResultToolStripMenuItem.Enabled = true;
				clearQueryResultToolStripMenuItem.Enabled = true;
				addQueryToolStripMenuItem.Enabled = true;
				addQueryToolStripMenuItem1.Enabled = true;
			}
			else
			{
				removeAllToolStripMenuItem.Enabled = false;
				removeAllToolStripMenuItem1.Enabled = false;
				executeAllQueryAS2000ToolStripMenuItem1.Enabled = false;
				executeAllQueryAS2005ToolStripMenuItem1.Enabled = false;
				executeAllQueryAS2000ToolStripMenuItem.Enabled = false;
				executeAllQueryAS2005ToolStripMenuItem.Enabled = false;
				compareQueryResultToolStripMenuItem1.Enabled = false;
				clearQueryResultToolStripMenuItem1.Enabled = false;
				compareQueryResultToolStripMenuItem.Enabled = false;
				clearQueryResultToolStripMenuItem.Enabled = false;
				addQueryToolStripMenuItem.Enabled = true;
				addQueryToolStripMenuItem1.Enabled = true;
			}
			projectStatus = true;
		}
		#endregion

		#region private void asAddQueryForm_QueriesAdded()
		/// <summary>
		/// Raise event when queries added to the project file
		/// </summary>
		private void asAddQueryForm_QueriesAdded()
		{
			removeAllToolStripMenuItem.Enabled = true;
			removeAllToolStripMenuItem1.Enabled = true;
			compareQueryResultToolStripMenuItem1.Enabled = true;
			clearQueryResultToolStripMenuItem1.Enabled = true;
			compareQueryResultToolStripMenuItem.Enabled = true;
			clearQueryResultToolStripMenuItem.Enabled = true;
			executeAllQueryAS2000ToolStripMenuItem1.Enabled = true;
			executeAllQueryAS2005ToolStripMenuItem1.Enabled = true;
			executeAllQueryAS2000ToolStripMenuItem.Enabled = true;
			executeAllQueryAS2005ToolStripMenuItem.Enabled = true;
		}
		#endregion

		#region private void asQueryListForm_QueriesRemoved()
		/// <summary>
		/// Raise event when queries removed from projectfile
		/// </summary>

		private void asQueryListForm_QueriesRemoved()
		{
			removeAllToolStripMenuItem.Enabled = false;
			removeAllToolStripMenuItem1.Enabled = false;
			compareQueryResultToolStripMenuItem1.Enabled = false;
			clearQueryResultToolStripMenuItem1.Enabled = false;
			compareQueryResultToolStripMenuItem.Enabled = true;
			clearQueryResultToolStripMenuItem.Enabled = false;
			executeAllQueryAS2000ToolStripMenuItem1.Enabled = false;
			executeAllQueryAS2005ToolStripMenuItem1.Enabled = false;
			executeAllQueryAS2000ToolStripMenuItem.Enabled = false;
			executeAllQueryAS2005ToolStripMenuItem.Enabled = false;
		}
		#endregion

		#region private void exitToolStripMenuItem_Click(object sender, EventArgs e)
		/// <summary>
		/// To close the project
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void exitToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.Close();
		}
		#endregion

		#region private void importMDXQueryToolStripMenuItem_Click(object sender, EventArgs e)
		/// <summary>
		/// To load Add Query Form
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void importMDXQueryToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ShowAddQuery();
		}
		#endregion

		#region private void addQueryToolStripMenuItem1_Click(object sender, EventArgs e)
		/// <summary>
		/// To load Add Query Form
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void addQueryToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			ShowAddQuery();
		}
		#endregion

		#region private void openToolStripMenuItem_Click(object sender, EventArgs e)
		/// <summary>
		/// To open configuration form
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void openToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (projectStatus)
			{
				DialogResult result = MessageBox.Show("This action will close the currently opened project. Do you want to continue ?", "AS Upgrade Verification Tool", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
				if (result == DialogResult.OK)
				{

					CleanUPPreviousProjectDetails();
					ShowConfiguration();
					configForm.Text = "Open Project";
				}
			}
			else
			{
				ShowConfiguration();
				configForm.Text = "Open Project";
			}
		}
		#endregion

		#region private void removeAllToolStripMenuItem_Click(object sender, EventArgs e)
		/// <summary>
		/// Rmove all queries and correspoding details that added to the project
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void removeAllToolStripMenuItem_Click(object sender, EventArgs e)
		{
			RemoveAllQueries();

		}
		#endregion

		#region private void removeAllToolStripMenuItem1_Click(object sender, EventArgs e)
		/// <summary>
		/// Rmove all queries and correspoding details that added to the project
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void removeAllToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			RemoveAllQueries();
		}
		#endregion

		#region private void executeAllQueryAS2000ToolStripMenuItem_Click(object sender, EventArgs e)
		/// <summary>
		/// Execute all queries against Analysis Services 2000 and save result to project file
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void executeAllQueryAS2000ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			show2005 = false;
			ExecuteQuery("AS2K");
		}
		#endregion

		#region private void executeAllQueryAS2005ToolStripMenuItem_Click(object sender, EventArgs e)
		/// <summary>
		/// Execute all queries against Analysis Services 2005 and save result to project file
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void executeAllQueryAS2005ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			show2005 = true;
			ExecuteQuery("AS2K5");
		}
		#endregion

		#region private void executeAllQueryAS2000ToolStripMenuItem1_Click(object sender, EventArgs e)
		/// <summary>
		/// Execute all queries against Analysis Services 2000 and save result to project file
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void executeAllQueryAS2000ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			show2005 = false;
			ExecuteQuery("AS2K");
		}
		#endregion

		#region private void executeAllQueryAS2005ToolStripMenuItem1_Click(object sender, EventArgs e)
		/// <summary>
		/// Execute all queries against Analysis Services 2000 and save result to project file
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void executeAllQueryAS2005ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			show2005 = true;			
			ExecuteQuery("AS2K5");
		}
		#endregion

		#region private void compareQueryResultToolStripMenuItem_Click(object sender, EventArgs e)
		private void compareQueryResultToolStripMenuItem_Click(object sender, EventArgs e)
		{
			CompareQueryResult();
		}
		#endregion

		#region private void compareQueryResultToolStripMenuItem1_Click(object sender, EventArgs e)

		private void compareQueryResultToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			Cursor.Current = Cursors.WaitCursor;
			CompareQueryResult();
			Cursor.Current = Cursors.Default;

		}
		#endregion

		#region private void clearQueryResultToolStripMenuItem_Click(object sender, EventArgs e)
		private void clearQueryResultToolStripMenuItem_Click(object sender, EventArgs e)
		{
			ClearQueryInfo();
		}
		#endregion

		#region private void clearQueryResultToolStripMenuItem1_Click(object sender, EventArgs e)
		private void clearQueryResultToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			ClearQueryInfo();
		}
		#endregion

		#region private void RemoveAllQueries()
		/// <summary>
		/// Method to remove all queries from the project file
		/// </summary>
		private void RemoveAllQueries()
		{
			DialogResult result = MessageBox.Show("Do you want to remove all queries from project?", "AS Upgrade Verification Tool", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
			if (result == DialogResult.OK)
			{
				XmlDocument xmldomProjectFile = ProjectFile.GetProjectDetails(projectDetails.ProjectLocation + "\\" + projectDetails.ProjectFileName);
				xmldomProjectFile.SelectSingleNode("ProjectFile/MDXQueries").InnerText = "";
				xmldomProjectFile.SelectSingleNode("ProjectFile/TotalQueries").InnerText = "0";
				xmldomProjectFile.SelectSingleNode("ProjectFile/QueriesPassed").InnerText = "0";
				xmldomProjectFile.SelectSingleNode("ProjectFile/QueriesFailed").InnerText = "0";
				ProjectFile.SetProjectDetails(xmldomProjectFile, projectDetails.ProjectLocation + "\\" + projectDetails.ProjectFileName);
				removeAllToolStripMenuItem.Enabled = false;
				removeAllToolStripMenuItem1.Enabled = false;
				compareQueryResultToolStripMenuItem1.Enabled = false;
				clearQueryResultToolStripMenuItem1.Enabled = false;
				compareQueryResultToolStripMenuItem.Enabled = false;
				clearQueryResultToolStripMenuItem.Enabled = false;
				executeAllQueryAS2000ToolStripMenuItem1.Enabled = false;
				executeAllQueryAS2005ToolStripMenuItem1.Enabled = false;
				executeAllQueryAS2000ToolStripMenuItem.Enabled = false;
				executeAllQueryAS2005ToolStripMenuItem.Enabled = false; 
				ShowQueryList();
			}
		}
		#endregion

		#region private void ShowConfiguration()
		/// <summary>
		/// To load configuration form
		/// </summary>
		private void ShowConfiguration()
		{
			if (compareForm != null && compareForm.CanFocus == true)
				compareForm.Close();
			if (addQueryForm != null && addQueryForm.CanFocus == true)
				addQueryForm.Hide();
			if (queryListForm != null && queryListForm.CanFocus == true)
				queryListForm.Close();
			if (configForm != null)
			{
				configForm.Close();
			}
			ASConfigForm configuration = new ASConfigForm();
			configuration.MdiParent = this;
			configuration.FileFound += new EventHandler<ProjectFileFoundEventArgs>(FileFound);
			configForm = configuration;
			configuration.Show();
		}
		#endregion

		#region public void ShowAddQuery()
		/// <summary>
		/// Method to show ADD Query Form
		/// </summary>
		public void ShowAddQuery()
		{
			if (configForm != null && configForm.CanFocus == true)
				configForm.Hide();
			if (compareForm != null && compareForm.CanFocus == true)
				compareForm.Close();
			if (queryListForm != null && queryListForm.CanFocus == true)
				queryListForm.Close();
			if (addQueryForm != null && addQueryForm.CanFocus)
			{
				addQueryForm.WindowState = FormWindowState.Maximized;
				addQueryForm.Focus();
			}
			else
			{
				
				ASAddQueryForm asAddQueryForm = new ASAddQueryForm(projectDetails);
				asAddQueryForm.QueriesAdded +=new ASAddQueryForm.QueriesAddedEvent(asAddQueryForm_QueriesAdded);
				addQueryForm = asAddQueryForm;
				addQueryForm.MdiParent = this;
				addQueryForm.Show();
			}
		}
		#endregion

		#region private void ShowQueryList()
		/// <summary>
		/// Method to show Query List Form
		/// </summary>
		private void ShowQueryList()
		{
			if (configForm != null && configForm.CanFocus == true)
				configForm.Hide();
			if (compareForm != null && compareForm.CanFocus == true)
				compareForm.Close();
			if (addQueryForm != null && addQueryForm.CanFocus == true)
				addQueryForm.Hide();
			if (queryListForm != null && queryListForm.CanFocus)
			{
				queryListForm.Dispose();
			}
			ASQueryListForm asQueryListForm=new ASQueryListForm(projectDetails, this);
			asQueryListForm.QueriesRemoved +=new ASQueryListForm.QueriesRemovedEvent(asQueryListForm_QueriesRemoved);
			queryListForm = asQueryListForm;
			queryListForm.MdiParent = this;
			queryListForm.Show();
		}
		#endregion

		#region private void ShowCompareForm()
		/// <summary>
		/// Method to show Comparison Result Form
		/// </summary>
		private void ShowCompareForm()
		{
			if (configForm != null && configForm.CanFocus == true)
				configForm.Hide();
			if (addQueryForm != null && addQueryForm.CanFocus == true)
				addQueryForm.Hide();
			if (queryListForm != null && queryListForm.CanFocus == true)
				queryListForm.Close();
			if (compareForm != null && compareForm.CanFocus)
			{
				compareForm.Close();
				compareForm = new ASCompareForm(projectDetails);
				compareForm.MdiParent = this;
				compareForm.Show();
			}
			else
			{
				compareForm = new ASCompareForm(projectDetails);
				compareForm.MdiParent = this;
				compareForm.Show();
			}
		}
		#endregion

		#region private void ClearQueryInfo()
		/// <summary>
		/// Method to clear all queries and its correspodning details from the project
		/// </summary>
		private void ClearQueryInfo()
		{

			XmlDocument xmlDomProjectContent = ProjectFile.GetProjectDetails(projectDetails.ProjectLocation + "\\" + projectDetails.ProjectFileName);
			if (xmlDomProjectContent.SelectSingleNode("ProjectFile/MDXQueries").InnerText.Trim().Length != 0)
			{
				DialogResult result = MessageBox.Show("Do you want to clear all the query result?", "AS Upgrade Verification Tool", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
				if (result == DialogResult.OK)
				{
					

					foreach (XmlNode xmlNodeQuery in xmlDomProjectContent.SelectSingleNode("ProjectFile/MDXQueries"))
					{
						xmlNodeQuery.SelectSingleNode("AS2KResult").InnerText = "";
						xmlNodeQuery.SelectSingleNode("AS2K5Result").InnerText = "";
						xmlNodeQuery.SelectSingleNode("AS2KQueryStatus").InnerText = "Query not Executed";
						xmlNodeQuery.SelectSingleNode("AS2K5QueryStatus").InnerText = "Query not Executed";
						xmlNodeQuery.SelectSingleNode("AS2KExecDuration").InnerText = "";
						xmlNodeQuery.SelectSingleNode("AS2K5ExecDuration").InnerText = "";
						xmlNodeQuery.SelectSingleNode("ComparisonResult").InnerText = "Not Compared";
					}
					xmlDomProjectContent.SelectSingleNode("ProjectFile/QueriesPassed").InnerText = "0";
					xmlDomProjectContent.SelectSingleNode("ProjectFile/QueriesFailed").InnerText = "0";

					ProjectFile.SetProjectDetails(xmlDomProjectContent, projectDetails.ProjectLocation + "\\" + projectDetails.ProjectFileName);
					ShowCompareForm();
				}
			}
			else
			{
				MessageBox.Show("Query Result does not exist", "AS Upgrade Verification Tool", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
			}
		}
		#endregion

		#region private void LoadForms()
		/// <summary>
		/// Method to load Forms according to the TreeView Selection
		/// </summary>
		private void LoadForms()
		{
			string node = mainTreeView.SelectedNode.Text;
			switch (node)
			{
				case "Configuration":
					//mainTreeView.SelectedNode = mainTreeView.Nodes[0];                    
					if (compareForm != null && compareForm.CanFocus == true)
						compareForm.Close();
					if (addQueryForm != null && addQueryForm.CanFocus == true)
						addQueryForm.Hide();
					if (queryListForm != null && queryListForm.CanFocus == true)
						queryListForm.Close();
					
					if (configForm != null && configForm.CanFocus == true)
					{
						configForm.WindowState = FormWindowState.Maximized;
						configForm.Focus();
					}
					else
					{
						configForm = new ASConfigForm(projectDetails);
						configForm.MdiParent = this;
						configForm.Text = "Configuration";
						configForm.Show();
					}
					
					break;
				case "Results":
					ShowCompareForm();
					break;
				case "Queries":
					ShowQueryList();
					break;
				default:
					break;
			}
		}
		#endregion

		#region private void ExecuteQuery(string instance)
		/// <summary>
		/// Method to execute all queries result and save result to project file
		/// </summary>
		/// <param name="instance"></param>
		private void ExecuteQuery(string instance)
		{

			Cursor.Current = Cursors.WaitCursor;
			AnalysisService asConn = new AnalysisService();
			try
			{
				XmlDocument xmlDomProjectContent = ProjectFile.GetProjectDetails(projectDetails.ProjectLocation + "\\" + projectDetails.ProjectFileName);
				if (xmlDomProjectContent.SelectSingleNode("ProjectFile/MDXQueries").InnerText.Trim().Length == 0)
					ShowQueryList();
				else
				{
					if (instance == "AS2K")
					{
						connStatus = asConn.TestConnection(projectDetails.AS2000, projectDetails.DatabaseName);
						if (connStatus)
						{
							if (xmlDomProjectContent.SelectSingleNode("ProjectFile/MDXQueries/MDXQuery[AS2KQueryStatus='Execution Succeeded']") != null)
							{
								DialogResult result = MessageBox.Show("Do you want to clear the previously executed query result?", "AS Upgrade Verification Tool", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
								if (result == DialogResult.OK)
								{
									AnalysisService analysisService = new AnalysisService();
									analysisService.ExecuteQueries(instance, projectDetails);
									ShowQueryList();
								}
								else ShowQueryList();
							}
							else
							{
								AnalysisService analysisService = new AnalysisService();
								analysisService.ExecuteQueries(instance, projectDetails);
								ShowQueryList();
							}
						}
						else
						{
							throw new CustomAppException("customException17");
						}
					}
					else if (instance == "AS2K5")
					{
						connStatus = asConn.TestConnection(projectDetails.AS2005, projectDetails.DatabaseName);
						if (connStatus)
						{
							if (xmlDomProjectContent.SelectSingleNode("ProjectFile/MDXQueries/MDXQuery[AS2K5QueryStatus='Execution Succeeded']") != null)
							{
								DialogResult result = MessageBox.Show("Do you want to clear the previously executed query result?", "AS Upgrade Verification Tool", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
								if (result == DialogResult.OK)
								{
									AnalysisService analysisService = new AnalysisService();
									analysisService.ExecuteQueries(instance, projectDetails);
									ShowQueryList();
								}
								else ShowQueryList();
							}
							else
							{
								AnalysisService analysisService = new AnalysisService();
								analysisService.ExecuteQueries(instance, projectDetails);
								ShowQueryList();
							}
						}
						else
						{
							throw new CustomAppException("customException17");
						}
					}
				}
			}
			catch (CustomAppException ex)
			{
				ExceptionManager.Publish(ex);
			}
			catch (Exception ex)
			{
				EventLog.WriteEntry("AS Upgrade Verification Tool", ex.ToString(), EventLogEntryType.Error);
			}
			Cursor.Current = Cursors.Default;
		}
		#endregion

		#region private void CompareQueryResult()
		/// <summary>
		/// Method to compare result of all quries and save to project file
		/// </summary>
		private void CompareQueryResult()
		{
			XmlDocument xmlDomProjectContent = ProjectFile.GetProjectDetails(projectDetails.ProjectLocation + "\\" + projectDetails.ProjectFileName);
			if (xmlDomProjectContent.SelectSingleNode("ProjectFile/MDXQueries").InnerText.Trim().Length != 0)
			{
				if (xmlDomProjectContent.SelectSingleNode("ProjectFile/MDXQueries/MDXQuery[ComparisonResult='Same Result']") != null)
				{
					DialogResult result = MessageBox.Show("Comparison results already exist, Do you wish to destroy the old comparison result?", "AS Upgrade Verification Tool", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
					if (result == DialogResult.OK)
					{
						AnalysisService.CompareQuery(projectDetails);
						ShowCompareForm();
					}
				}
				else
				{
					AnalysisService.CompareQuery(projectDetails);
					ShowCompareForm();
				}
			}
			else
			{
				MessageBox.Show("Query Result does not exist", "AS Upgrade Verification Tool", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
			}
		}
		#endregion

		#region private void heplTopicsToolStripMenuItem_Click(object sender, EventArgs e)

		private void heplTopicsToolStripMenuItem_Click(object sender, EventArgs e)
		{
            Help.ShowHelp(this.Owner, AppDomain.CurrentDomain.BaseDirectory  + "\\..\\..\\ASUV.chm", HelpNavigator.TableOfContents);
		}

		#endregion

		#region private void CleanPreviousProjectDetails()

		private void CleanUPPreviousProjectDetails()
		{
			mainTreeView.Nodes[0].Nodes.Clear();

			removeAllToolStripMenuItem.Enabled = false;
			removeAllToolStripMenuItem1.Enabled = false;
			executeAllQueryAS2000ToolStripMenuItem1.Enabled = false;
			executeAllQueryAS2005ToolStripMenuItem1.Enabled = false;
			executeAllQueryAS2000ToolStripMenuItem.Enabled = false;
			executeAllQueryAS2005ToolStripMenuItem.Enabled = false;
			compareQueryResultToolStripMenuItem1.Enabled = false;
			clearQueryResultToolStripMenuItem1.Enabled = false;
			compareQueryResultToolStripMenuItem.Enabled = false;
			clearQueryResultToolStripMenuItem.Enabled = false;
			addQueryToolStripMenuItem.Enabled = false;
			addQueryToolStripMenuItem1.Enabled = false;
			
			if (addQueryForm != null && addQueryForm.CanFocus)
			{
				addQueryForm.Close();
			}
			if (configForm != null)
			{
				configForm.Close();
			}
			if (queryListForm != null && queryListForm.CanFocus)
			{
				queryListForm.Close();
			}
			if (compareForm != null && compareForm.CanFocus)
			{
				compareForm.Close();
			}

		}
		#endregion

		
	}

   

}